package com.aaa.stock.service.Impl;

import com.aaa.entity.Provider;
import com.aaa.stock.dao.ProviderDao;
import com.aaa.stock.service.ProviderService;
import com.aaa.stock.vo.ProviderVo;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Objects;

@Service
public class ProviderServiceImpl extends ServiceImpl<ProviderDao, Provider> implements ProviderService {
    @Autowired
    private ProviderDao providerDao;
    //分页查询
    @Override
    public Result<IPage<Provider>> findByPage(Integer currentPage, Integer pageSize, ProviderVo providerVo) {
        IPage<Provider> page=new Page<>(currentPage,pageSize);
        QueryWrapper<Provider> wrapper=new QueryWrapper<>();
        if (StringUtils.hasText(providerVo.getProviderName())){
            wrapper.like("provider_name",providerVo.getProviderName());
        }
        if (StringUtils.hasText(providerVo.getContactName())){
            wrapper.like("contact_name",providerVo.getContactName());
        }
        if (StringUtils.hasText(providerVo.getContactTel())){
            wrapper.like("contact_tel",providerVo.getContactTel());
        }
        if (StringUtils.hasText(providerVo.getStatus())){
            wrapper.eq("status",providerVo.getStatus());
        }

        IPage<Provider> page1 = providerDao.selectPage(page, wrapper);
        return new Result<IPage<Provider>>(200,"查询用户成功",page1);
    }


    //查询
    @Override
    public Result<List<Provider>> getAll() {
        List<Provider> providers = providerDao.selectList(null);
        return new Result<>(200,"查询",providers);
    }
}
